package com.huanuo.internetofthings.service.role;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.unicorn.framework.base.base.AbstractService;
import org.unicorn.framework.core.SysCode;
import org.unicorn.framework.core.exception.PendingException;

import com.huanuo.internetofthings.bo.role.Role;
import com.huanuo.internetofthings.bo.userRole.UserRole;

@Service
public class UserRoleFacadeService extends AbstractService {
	@Autowired
	private RoleService roleService;
	@Autowired
	private UserRoleService userRoleService;
	/**
	 * 获取用户角色列表
	 * @param userRole
	 * @return
	 * @throws PendingException
	 */
	public List<String> getUserRoleList(UserRole userRole) throws PendingException {
		try{
			List<UserRole> userRoleList=userRoleService.selectUserRoleList(userRole);
			List<Integer> roleIds=userRoleList.stream().map(ur->ur.getRoleId()).collect(Collectors.toList());
			List<Role> roleList=roleService.selectRoleListByIds(roleIds);
			return roleList.stream().map(role->role.getRoleIdentity()).collect(Collectors.toList());
		}catch(PendingException pe){
			throw pe;
		}catch(Exception e){
			error("获取用户角色列表",e);
			throw new PendingException(SysCode.SYS_FAIL);
		}
	}
}